define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.user/index',
        add_url: 'user.user/add',
        edit_url: 'user.user/edit',
        delete_url: 'user.user/delete',
        export_url: 'user.user/export',
        imports_url: 'user.user/imports',
        modify_url: 'user.user/modify',
        batchs_url: 'user.user/batchCourse',
        settopic_url: 'user.user/settopic',
        batpictures_url: 'user.user/batpictures',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: [
                    'refresh',
                    'imports',
                    'batpictures',
                    'export',
                    'batchs'
                ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id'},
                    {field: 'name', title: '姓名'},
                    {field: 'mobile', title: '手机号'},
                    {field: 'unit', title: '单位'},
                    {field: 'section', title: '部门'},
                    {field: 'create_time', title: '创建时间'},
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            'edit',
                            [{
                                text: '设置课程',
                                url: init.settopic_url,
                                method: 'open',
                                auth: 'settopic',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }],
                            'delete'
                        ]
                    }
                ]],
            });
            layui.use(['layer','upload'], function () {
                var upload = layui.upload;
                //指定允许上传的文件类型
                upload.render({
                    elem: '#uploadExcel'
                    ,url: 'imports' //此处为所上传的请求路径
                    ,accept: 'file' //普通文件
                    ,exts: 'xls|excel|xlsx' //只允许上传压缩文件
                    ,done: function(res){
                        if(res.code == 1){
                            layer.msg(res.message);
                        }else {
                            layer.msg(res.message);
                        }
                        window.location.reload()
                    }
                });
                upload.render({
                    elem: '#batpictures'
                    ,url: 'batpictures' //此处为所上传的请求路径
                    ,accept: 'file' //普通文件
                    ,exts: 'zip' //只允许上传压缩文件
                    ,done: function(res){
                        if(res.code == 1){
                            layer.msg(res.message);
                        }else {
                            layer.msg(res.message);
                        }
                        window.location.reload()
                    }
                });
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});